package com.yan.demo04;

import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.springframework.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

/**
 * @author yanheng
 * @data 2020/1/19 14:44
 */
public class CglibProxyFactory{
    private Object targetObject;
    public Object getProxyInstance(Object targetObject){
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "F:\\class");
        this.targetObject = targetObject;
        Enhancer en = new Enhancer();
        en.setSuperclass(targetObject.getClass());
        en.setCallback(new CglibProxyClass());
        //OperationClassFilter 中的返回值代表使用Callbacks指定的数组下标对应的拦截器
        en.setCallbackFilter(new CglibProxyClassFilter());
        Object o = en.create();
        return o;
    }
}
